/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package StartUp;

/**
 *
 * @author Mih
 */
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.TextArea;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import bluej.extensions.BClass;
import bluej.extensions.BField;
import bluej.extensions.BMethod;
import bluej.extensions.ClassNotFoundException;
import bluej.extensions.ProjectNotOpenException;

public class ClassInfo extends JFrame {

    private static final long serialVersionUID = 1L;
    private JPanel jContentPane = null;
    private TextArea textArea = null;
    private JButton buttonOk = null;
    private BClass curClass;

    /**
     * This is the default constructor
     */
    public ClassInfo(BClass bclass) {
        super();
        initialize();
        curClass = bclass;
        getInfo();
    }

    /**
     * This method initializes this
     * 
     * @return void
     */
    private void initialize() {
        this.setSize(400, 350);
        this.setContentPane(getJContentPane());
        this.setTitle("Class Info");
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }

    /**
     * This method initializes jContentPane
     * 
     * @return javax.swing.JPanel
     */
    private JPanel getJContentPane() {
        if (jContentPane == null) {
            jContentPane = new JPanel();
            jContentPane.setLayout(null);
            jContentPane.add(getTextArea(), null);
            jContentPane.add(getButtonOk(), null);
        }
        return jContentPane;
    }

    /**
     * This method initializes textArea	
     * 	
     * @return java.awt.TextArea	
     */
    private TextArea getTextArea() {
        if (textArea == null) {
            textArea = new TextArea();
            textArea.setBounds(new Rectangle(3, 2, 380, 249));
            textArea.setBackground(this.getBackground());
            textArea.setEditable(false);
        }
        return textArea;
    }

    /**
     * This method initializes buttonOk	
     * 	
     * @return javax.swing.JButton	
     */
    private JButton getButtonOk() {
        if (buttonOk == null) {
            buttonOk = new JButton();
            buttonOk.setBounds(new Rectangle(170, 265, 60, 30));
            buttonOk.setText("Ok");
            buttonOk.addActionListener(new Events());
        }
        return buttonOk;
    }

    private void getInfo() {
        String fields = "", methods = "";

        try {
            if (curClass.getFields().length > 0) {
                fields = "Fields:\n\n";
                for (BField f : curClass.getFields()) {
                    fields += "   -" + f.getName() + "\n";
                }
                fields += "\n___________________________________________________________\n";
            }
        } catch (ProjectNotOpenException e1) {
            // TODO Auto-generated catch block
        } catch (ClassNotFoundException e1) {
            // TODO Auto-generated catch block
        }


        try {
            methods = "All Methods:\n\n";
            for (BMethod m : curClass.getMethods()) {
                methods += "   -" + m.getName() + "\n";
            }
        } catch (ProjectNotOpenException e) {
            // TODO Auto-generated catch block
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
        }
        textArea.setText(fields + methods);
        textArea.setCaretPosition(0);
    }

    class Events implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            dispose();
        }
    }
}
